package it.interazionemultimodale.twitterrecognizer.ui;

import it.interazionemultimodale.twitterrecognizer.R;
import it.interazionemultimodale.twitterrecognizer.utility.Methods;
import it.interazionemultimodale.twitterrecognizer.utility.Variables;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity
{	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//Create shared preferences object
		Variables.mSharedPreferences = getApplicationContext().getSharedPreferences(Variables.SHARED_PREFERENCES_NAME, 0);
		
		if (Variables.mSharedPreferences.getBoolean(Variables.KEY_TWITTER_LOGIN, false))
		{
			startActivity(new Intent(this, HomeActivity.class));
			finish();
		}
		else
		{	
			if (!Methods.checkSpeechRecognition(this))
			{
				Button onGoingLoginButton = (Button)findViewById(R.id.onGoingLoginButton);
				onGoingLoginButton.setEnabled(false);
				Toast.makeText(this, "Nessun servizio di riconoscimento vocale presente", Toast.LENGTH_LONG).show();
			}
		}
	}

	//On going to login button listener
	public void goingToLogin(View view)
	{
		if (Methods.checkInternetConnection(this))
		{
			Intent intent = new Intent(this, AuthorizationActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
		}
		else
			Toast.makeText(this,"Nessuna connessione internet disponibile", Toast.LENGTH_LONG).show();
	}
	
}
